<template>
  <div class="peosonResultListBox main w" style="background-color:#fff">
    <p class="peosonResultTitle">评价系统 - 题目管理</p>
    <!-- 新增题目 -->
    <div class="addBtnBox" style>
      <div class="item">
        <el-button type="success" @click="showAddState(departmentForm)" icon="el-icon-plus">新增评价题目</el-button>
      </div>
    </div>
    <!-- 列表主体 -->
    <el-table
      :data="questionList"
      border
      class="adminTable"
      :row-class-name="tableRowClassName"
      :header-cell-style="elementStyleObj"
    >
      <el-table-column type="index" label="序号" width="50" header-align="center" align="center"></el-table-column>
      <el-table-column
        prop="surveyId "
        label="评价类型"
        width="170"
        header-align="center"
        align="center"
      >
        <template slot-scope="scope">
          <template v-if="questionList[scope.$index].surveyId  == 1">
            <span>集体评价</span>
          </template>
          <template v-if="questionList[scope.$index].surveyId  == 2">
            <span>个人评价</span>
          </template>
        </template>
      </el-table-column>
      <el-table-column prop="title" label="题目" header-align="center" align="center"></el-table-column>
      <el-table-column
        prop="priority"
        label="题目展示顺序"
        width="85"
        header-align="center"
        align="center"
      ></el-table-column>
      <el-table-column prop="typeId" label="题目类型" width="130" header-align="center" align="center">
        <template slot-scope="scope">
          <template v-if="questionList[scope.$index].typeId  == 1">
            <span>单选题</span>
          </template>
          <template v-if="questionList[scope.$index].typeId  == 2">
            <span>简答题</span>
          </template>
        </template>
      </el-table-column>
      <el-table-column prop="enable " label="是否启用" width="70" header-align="center" align="center">
        <template slot-scope="scope">
          <template v-if="questionList[scope.$index].enable  == true">
            <i class="el-icon-check" style="color:#13ce66;font-size:28px;fontWeight: 600;"></i>
          </template>
          <template v-else>
            <i class="el-icon-minus" style="font-size:28px;fontWeight: 600;"></i>
          </template>
        </template>
      </el-table-column>
      <el-table-column
        label="编 辑"
        filter-placement="bottom-end"
        width="180"
        header-align="center"
        align="center"
      >
        <template slot-scope="scope">
          <el-button
            v-if="questionList[scope.$index].surveyId  == 1"
            size="mini"
            type="primary"
            @click="showEditDepartmentQuestion(scope.$index, scope.row)"
            icon="el-icon-edit"
          >编 辑</el-button>
          <el-button
            v-if="questionList[scope.$index].surveyId  == 2"
            size="mini"
            type="success"
            @click="showEditPersonQuestion(scope.$index, scope.row)"
            icon="el-icon-edit"
          >编 辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 弹窗表格 -->
    <!-- 新增评价题目 -->
    <el-dialog
      title="新增评价题目"
      :visible.sync="addState"
      size="large"
      @close="closeDialog"
      width="80%"
    >
      <el-tabs type="border-card">
        <el-tab-pane label="集体评价">
          <el-form
            :model="departmentForm"
            ref="departmentForm"
            :rules="rules"
            label-width="160px"
            v-loading="addLoading"
            style="margin-top:20px;"
          >
            <el-row>
              <el-col :span="13">
                <el-form-item label="题目" prop="title">
                  <el-input v-model="departmentForm.title" placeholder="请输入题目"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="7">
                <el-form-item label="题目展示顺序" prop="priority">
                  <el-input v-model="departmentForm.priority" placeholder="数字越大排序越靠后"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8"></el-col>
            </el-row>
            <el-row>
              <el-col :span="20">
                <el-form-item v-if="departmentForm.detail != null" label="题目详情介绍">
                  <el-input type="textarea" v-model="departmentForm.detail"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="6">
                <el-form-item label="是否启用">
                  <el-switch v-model="departmentForm.enable"></el-switch>
                </el-form-item>
              </el-col>
              <el-col :span="5">
                <el-form-item label="是否必填">
                  <el-switch v-model="departmentForm.necessary"></el-switch>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="6">
                <el-form-item label="是否参与集体统计">
                  <el-switch v-model="departmentForm.isOverallStatistics"></el-switch>
                </el-form-item>
              </el-col>
              <el-col :span="14">
                <el-form-item v-if="departmentForm.isOverallStatistics == true" label="统计权重">
                  <el-input v-model="departmentForm.weight "></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="6">
                <el-form-item label="是否展示评价详情">
                  <el-switch v-model="departmentForm.showDetail"></el-switch>
                </el-form-item>
              </el-col>
              <el-col :span="14">
                <el-form-item v-if="departmentForm.showDetail == true" label="数据展示名字">
                  <el-input v-model="departmentForm.statisticTitle "></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-form-item label="作风建设评价表分类">
              <el-radio-group v-model="departmentForm.statisticTitleId">
                <!-- <div class="reminder">
                  <img src="../../assets/49.png" alt="">
                </div>-->
                <el-tooltip
                  class="item"
                  effect="dark"
                  content="下载作风建设评价表时，统计结果归属评价内容栏"
                  placement="bottom-end"
                >
                  <el-radio-button class="statisticTitleId" label="1">规范、态度、成效</el-radio-button>
                </el-tooltip>
                <el-tooltip
                  class="item"
                  effect="dark"
                  content="下载作风建设评价表时，统计结果归属作风变化情况"
                  placement="bottom"
                >
                  <el-radio-button class="statisticTitleId" label="2">作风变化情况</el-radio-button>
                </el-tooltip>
                <el-tooltip class="item" effect="dark" content="不参与评价评分统计" placement="bottom-start">
                  <el-radio-button class="statisticTitleId" label="3">其它 (不参与)</el-radio-button>
                </el-tooltip>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="题目类型">
              <el-radio-group v-model="departmentForm.typeId">
                <el-radio-button label="1">单选题</el-radio-button>
                <el-radio-button label="2">简答题</el-radio-button>
              </el-radio-group>
            </el-form-item>
            <!-- 单选选项输入 -->
            <el-row class="selectManage" v-show="departmentForm.typeId == 1">
              <el-col :span="24">
                <el-form-item label>
                  <div>
                    <el-button type="success" @click="addDepartmentOption" icon="el-icon-plus">新增选项</el-button>
                  </div>
                </el-form-item>
                <el-row
                  v-for="(optionDtoList, index) in departmentForm.optionDtoList"
                  :key="optionDtoList.key"
                  class="selectManageItem"
                >
                  <el-col :span="8" style="margin-top:20px">
                    <el-form-item :label="'选项' + (index+1)">
                      <el-input v-model="optionDtoList.answerDesc"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8" style="margin-top:20px;margin-left:-50px;">
                    <el-form-item label="选项得分">
                      <el-input v-model="optionDtoList.score"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="6" style="margin-top:20px;">
                    <el-button
                      type="danger"
                      style="margin-left:30px;"
                      @click.prevent="removeDepartmentDomain(optionDtoList)"
                    >删 除</el-button>
                  </el-col>
                </el-row>
              </el-col>
            </el-row>
            <el-form-item style="margin-top:20px;">
              <el-button @click="addState = false">取 消</el-button>
              <el-button type="primary" @click="addDepartment(departmentForm)">确 定</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="个人评价">
          <el-form
            :model="personForm"
            ref="personForm"
            :rules="rules"
            label-width="160px"
            v-loading="addLoading"
            style="margin-top:20px;"
          >
            <el-row>
              <el-col :span="18">
                <el-form-item label="题目" prop="title">
                  <el-input v-model="personForm.title" placeholder="请输入题目"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="题目展示顺序" prop="priority">
                  <el-input v-model="personForm.priority" placeholder=" 数字越大排序越靠后"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="5">
                <el-form-item label="是否启用">
                  <el-switch v-model="personForm.enable"></el-switch>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="是否必填">
                  <el-switch v-model="personForm.necessary"></el-switch>
                </el-form-item>
              </el-col>
            </el-row>
            <el-form-item label="题目类型">
              <el-radio-group v-model="personForm.typeId">
                <el-radio-button label="1">单选题</el-radio-button>
                <el-radio-button label="2">简答题</el-radio-button>
              </el-radio-group>
            </el-form-item>
            <!-- 单选选项输入 -->
            <el-row class="selectManage" v-show="personForm.typeId == 1">
              <el-col :span="24">
                <el-form-item label>
                  <div>
                    <el-button type="success" @click="addPersonOption" icon="el-icon-plus">新增选项</el-button>
                  </div>
                </el-form-item>
                <el-row
                  v-for="(optionDtoList, index) in personForm.optionDtoList"
                  :key="optionDtoList.key"
                  class="selectManageItem"
                >
                  <el-col :span="8" style="margin-top:20px">
                    <el-form-item :label="'选项' + (index+1)">
                      <el-input v-model="optionDtoList.answerDesc"></el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="6" style="margin-top:20px;">
                    <el-button
                      type="danger"
                      style="margin-left:30px;"
                      @click.prevent="removePersonDomain(optionDtoList)"
                    >删 除</el-button>
                  </el-col>
                </el-row>
              </el-col>
            </el-row>
            <el-form-item style="margin-top:20px;">
              <el-button @click="addState = false">取 消</el-button>
              <el-button type="primary" @click="addPerson(personForm)">确 定</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>
      </el-tabs>
    </el-dialog>
    <!-- 编辑集体评价题目 -->
    <el-dialog
      title="编辑集体评价题目"
      :visible.sync="editDepState"
      size="large"
      @close="closeDialog"
      width="80%"
    >
      <el-form
        :model="departmentForm"
        ref="departmentForm"
        :rules="rules"
        label-width="160px"
        v-loading="addLoading"
        style="margin-top:0px;"
      >
        <el-row>
          <el-col :span="13">
            <el-form-item label="题目" prop="title">
              <el-input v-model="departmentForm.title" placeholder="请输入题目"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="题目展示顺序" prop="priority">
              <el-input v-model="departmentForm.priority" placeholder="数字越大排序越靠后"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8"></el-col>
        </el-row>
        <el-row>
          <el-col :span="20">
            <el-form-item v-if="departmentForm.detail != null" label="题目详情介绍">
              <el-input type="textarea" v-model="departmentForm.detail"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="是否启用">
              <el-switch v-model="departmentForm.enable"></el-switch>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="是否必填">
              <el-switch v-model="departmentForm.necessary"></el-switch>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="是否参与集体统计">
              <el-switch v-model="departmentForm.isOverallStatistics"></el-switch>
            </el-form-item>
          </el-col>
          <el-col :span="14">
            <el-form-item v-if="departmentForm.isOverallStatistics == true" label="统计权重">
              <el-input v-model="departmentForm.weight "></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="是否展示评价详情">
              <el-switch v-model="departmentForm.showDetail"></el-switch>
            </el-form-item>
          </el-col>
          <el-col :span="14">
            <el-form-item v-if="departmentForm.showDetail == true" label="数据展示名字">
              <el-input v-model="departmentForm.statisticTitle "></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="作风建设评价表分类">
          <el-radio-group v-model="departmentForm.statisticTitleId">
            <!-- <div class="reminder">
              <img src="../../assets/49.png" alt="">
            </div>-->
            <el-tooltip
              class="item"
              effect="dark"
              content="下载作风建设评价表时，统计结果归属评价内容栏"
              placement="bottom-end"
            >
              <el-radio-button class="statisticTitleId" label="1">规范、态度、成效</el-radio-button>
            </el-tooltip>
            <el-tooltip
              class="item"
              effect="dark"
              content="下载作风建设评价表时，统计结果归属作风变化情况"
              placement="bottom"
            >
              <el-radio-button class="statisticTitleId" label="2">作风变化情况</el-radio-button>
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="不参与评价评分统计" placement="bottom-start">
              <el-radio-button class="statisticTitleId" label="3">其它 (不参与)</el-radio-button>
            </el-tooltip>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="题目类型">
          <el-radio-group v-model="departmentForm.typeId">
            <el-radio-button disabled label="1">单选题</el-radio-button>
            <el-radio-button disabled label="2">简答题</el-radio-button>
          </el-radio-group>
        </el-form-item>
        <!-- 单选选项输入 -->
        <el-row class="selectManage" v-show="departmentForm.typeId == 1">
          <el-col :span="24">
            <el-row
              v-for="(optionDtoList, index) in departmentForm.optionDtoList"
              :key="optionDtoList.key"
              class="selectManageItem"
            >
              <el-col :span="8" style="margin-top:20px">
                <el-form-item :label="'选项' + (index+1)">
                  <el-input v-model="optionDtoList.answerDesc"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="8" style="margin-top:20px;margin-left:-50px;">
                <el-form-item label="选项得分">
                  <el-input v-model="optionDtoList.score"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-col>
        </el-row>
        <el-form-item style="margin-top:20px;">
          <el-button @click="editDepState = false">取 消</el-button>
          <el-button type="primary" @click="editDepartment(departmentForm)">确 定</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!-- 编辑个人评价题目 -->
    <el-dialog
      title="编辑个人评价题目"
      :visible.sync="editPersonState"
      size="large"
      @close="closeDialog"
      width="80%"
    >
      <el-form
        :model="personForm"
        ref="personForm"
        :rules="rules"
        label-width="160px"
        v-loading="addLoading"
        style="margin-top:0px;"
      >
        <el-row>
          <el-col :span="18">
            <el-form-item label="题目" prop="title">
              <el-input v-model="personForm.title" placeholder="请输入题目"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="题目展示顺序" prop="priority">
              <el-input v-model="personForm.priority" placeholder=" 数字越大排序越靠后"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="5">
            <el-form-item label="是否启用">
              <el-switch v-model="personForm.enable"></el-switch>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="是否必填">
              <el-switch v-model="personForm.necessary"></el-switch>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="题目类型:">
          <el-radio-group v-model="personForm.typeId">
            <el-radio-button disabled label="1">单选题</el-radio-button>
            <el-radio-button disabled label="2">简答题</el-radio-button>
          </el-radio-group>
        </el-form-item>
        <!-- 单选选项输入 -->
        <el-row class="selectManage" v-show="personForm.typeId == 1">
          <el-col :span="24">
            <el-row
              v-for="(optionDtoList, index) in personForm.optionDtoList"
              :key="optionDtoList.key"
              class="selectManageItem"
            >
              <el-col :span="8" style="margin-top:20px">
                <el-form-item :label="'选项' + (index+1)">
                  <el-input v-model="optionDtoList.answerDesc"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-col>
        </el-row>
        <el-form-item style="margin-top:20px;">
          <el-button @click="editPersonState = false">取 消</el-button>
          <el-button type="primary" @click="editPerson(personForm)">确 定</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<style scope>
.reminder img {
  width: 520px;
  height: auto;
  position: absolute;
  left: 220px;
  top: -134px;
  border: 1px solid #e8e8e8;
  box-shadow: 0px 1px 2px #bdbebe;
}

.selectManageItem {
  border-top: 1px solid #ebebeb;
  padding-top: -5px;
  padding-bottom: -5px;
}
.selectManage {
  height: 100%;
  width: 100%;
  background-color: rgba(246, 248, 250, 0.5);
  padding: 20px 5px 2px 5px;
  /* box-shadow: 0px 1px 1px #e3e4e9; */
}
.adminTable {
  font-family: "Microsoft" !important;
  width: 96%;
  margin: 10px 2% 30px;
  -webkit-box-shadow: 0px 6px 14px #e8e8e8;
  box-shadow: 0px 6px 14px #e8e8e8;
  cursor: pointer;
}
.adminTable2 {
  width: 85%;
}
.el-table .warning-row {
  background: #b5ebce;
}

.el-table .success-row {
  background: #f0f9eb;
}
</style>
<script>
export default {
  name: "adminQuestion",
  data() {
    return {
      //element 表头样式
      elementStyleObj: {
        background: "rgb(245, 249, 255) ",
        fontSize: "17px",
        color: "#434343"
      },
      questionList: [], //题目列表
      addState: false, //新增部门弹窗开关状态
      editDepState: false, //编辑部门弹窗开关状态
      editPersonState: false, //编辑部门弹窗开关状态
      addLoading: false, //懒加载
      // 集体题目新增
      departmentForm: {
        detail: "", //题目详情介绍
        enable: true, //是否启用
        id: "", //题目id
        isOverallStatistics: true, //是否参与集体统计
        necessary: false, //是否必填 1必填 0 非必填 ,
        //选项列表，当题目类型 为1 选项题时，必填 ,
        optionDtoList: [
          {
            answerDesc: "", //选项描述
            id: "", //选项id ,
            score: 0, //选项得分 当题目参与统计权重时，不能为空 ,
            tag: 0 // 选项是否积极 当选项为 满意 不满意 时，建议选择
          }
        ],
        overallStatistics: true,
        priority: 0, // 题目展示顺序
        showDetail: false, //展示评价详情(集体评价) 1展示，0不展示 ,
        statisticTitle: "", //数据展示title ,
        statisticTitleId: 1, //统计集体评价时的标题 1评价内容, 2作风变化情况 3其他不参与
        surveyId: 1, //评价类型 1集体评价，2个人评价 ,
        tag: false, //题目是否涉及内容积极性 仅当typeId = 2 即输入框题型时 ,
        title: "", //题目 ,
        typeId: 1, // 题目类型 1单选，2输入框 ,
        weight: 0 //统计权重(集体评价) 仅当 isOverallStatistics 为true参与统计时
      },
      //个人题目新增
      personForm: {
        detail: "", //题目详情介绍
        id: "",
        enable: false, //是否启用
        necessary: false, //是否必填 1必填 0 非必填 ,
        //选项列表，当题目类型 为1 选项题时，必填 ,
        optionDtoList: [
          {
            answerDesc: "", //选项描述
            id: "", //选项id ,
            tag: 0 // 选项是否积极 当选项为 满意 不满意 时，建议选择
          }
        ],
        priority: 0, // 题目展示顺序
        surveyId: 2, //评价类型 1集体评价，2个人评价 ,
        tag: false, //题目是否涉及内容积极性 仅当typeId = 2 即输入框题型时 ,
        title: "", //题目 ,
        typeId: 1 // 题目类型 1单选，2输入框 ,
      },
      // 表单验证
      rules: {}
    };
  },
  created() {
    this.getQuestionList();
  },
  methods: {
    //个人评价题目行换色
    tableRowClassName(row) {
      if (row.row.surveyId == 2) {
        return "success-row";
      }
      return "";
    },
    //编辑个人评价题目
    editPerson(personForm) {
      this.$refs.personForm.validate(valid => {
        if (valid) {
          this.addLoading = true;
          //  typeId: 1, // 题目类型 1单选，2输入框 ,
          // 如果是输入框则删除选项列表
          if (this.personForm.typeId == 2) {
            delete this.personForm.optionDtoList;
          }
          const url = "api/management/question/update";
          this.$axios.post(url, this.personForm).then(response => {
            this.addLoading = false;
            if (response.data.code == 0) {
              this.$message({
                showClose: false,
                message: "修改成功",
                type: "success",
                center: true, //文字居中
                duration: 1200
              });
              this.editPersonState = false;
              this.getQuestionList(); //重新加载列表
            } else {
              //失败
              this.$message({
                showClose: false,
                message: response.data.message,
                type: "error",
                center: true, //文字居中
                duration: 1200
              });
              return;
            }
          });
        } else {
          return false;
        }
      });
    },
    //编辑集体评价题目
    editDepartment(departmentForm) {
      this.$refs.departmentForm.validate(valid => {
        if (valid) {
          this.addLoading = true;
          //  typeId: 1, // 题目类型 1单选，2输入框 ,
          // 如果是输入框则删除选项列表
          if (this.departmentForm.typeId == 2) {
            delete this.departmentForm.optionDtoList;
          }
          const url = "api/management/question/update";
          this.$axios.post(url, this.departmentForm).then(response => {
            this.addLoading = false;
            if (response.data.code == 0) {
              this.$message({
                showClose: false,
                message: "修改成功",
                type: "success",
                center: true, //文字居中
                duration: 1200
              });
              this.editDepState = false;
              this.getQuestionList(); //重新加载列表
            } else {
              //失败
              this.$message({
                showClose: false,
                message: response.data.message,
                type: "error",
                center: true, //文字居中
                duration: 1200
              });
              return;
            }
          });
        } else {
          return false;
        }
      });
    },
    // 新增个人评价题目
    addPerson(personForm) {
      this.addQuestion(this.personForm);
    },
    // 新增集体题目
    addDepartment(departmentForm) {
      this.addQuestion(this.departmentForm);
    },
    // 新增题目
    addQuestion(addForm) {
      this.addLoading = true;
      //  typeId: 1, // 题目类型 1单选，2输入框 ,
      // 如果是输入框则删除选项列表
      if (addForm.typeId == 2) {
        delete addForm.optionDtoList;
      }
      const url = "api/management/question/insert";
      this.$axios.post(url, addForm).then(response => {
        this.addLoading = false;
        if (response.data.code == 0) {
          this.$message({
            showClose: false,
            message: "添加成功",
            type: "success",
            center: true, //文字居中
            duration: 1200
          });
          this.addState = false;
          this.getQuestionList(); //重新加载列表
        } else {
          //失败
          this.$message({
            showClose: false,
            message: response.data.message,
            type: "error",
            center: true, //文字居中
            duration: 1200
          });
          return;
        }
      });
    },
    //显示新增窗口
    showAddState(departmentForm) {
      this.addState = true;
      // 初始化集体表单
      this.departmentForm = {
        detail: "", //题目详情介绍
        enable: true, //是否启用
        isOverallStatistics: true, //是否参与集体统计
        necessary: false, //是否必填 1必填 0 非必填 ,
        //选项列表，当题目类型 为1 选项题时，必填 ,
        optionDtoList: [
          {
            answerDesc: "", //选项描述
            id: "", //选项id ,
            score: 0, //选项得分 当题目参与统计权重时，不能为空 ,
            tag: 0 // 选项是否积极 当选项为 满意 不满意 时，建议选择
          }
        ],
        overallStatistics: true,
        priority: 0, // 题目展示顺序
        showDetail: false, //展示评价详情(集体评价) 1展示，0不展示 ,
        statisticTitle: "", //数据展示title ,
        statisticTitleId: 1, //统计集体评价时的标题 1评价内容, 2作风变化情况 3其他不参与
        surveyId: 1, //评价类型 1集体评价，2个人评价 ,
        tag: false, //题目是否涉及内容积极性 仅当typeId = 2 即输入框题型时 ,
        title: "", //题目 ,
        typeId: 1, // 题目类型 1单选，2输入框 ,
        weight: 0 //统计权重(集体评价) 仅当 isOverallStatistics 为true参与统计时
      };
      //初始化个人
      this.personForm = {
        detail: "", //题目详情介绍
        id: "",
        enable: false, //是否启用
        necessary: false, //是否必填 1必填 0 非必填 ,
        //选项列表，当题目类型 为1 选项题时，必填 ,
        optionDtoList: [
          {
            answerDesc: "", //选项描述
            id: "", //选项id ,
            tag: 0 // 选项是否积极 当选项为 满意 不满意 时，建议选择
          }
        ],
        priority: 0, // 题目展示顺序
        surveyId: 2, //评价类型 1集体评价，2个人评价 ,
        tag: false, //题目是否涉及内容积极性 仅当typeId = 2 即输入框题型时 ,
        title: "", //题目 ,
        typeId: 1 // 题目类型 1单选，2输入框 ,
      };
    },
    //新增集体选项输入框
    addDepartmentOption() {
      this.departmentForm.optionDtoList.push({
        answerDesc: "",
        key: Date.now()
      });
    },
    //删除题目选项输入框
    removeDepartmentDomain(item) {
      var index = this.departmentForm.optionDtoList.indexOf(item);
      if (index !== -1) {
        this.departmentForm.optionDtoList.splice(index, 1);
      }
    },
    //新增个人选项输入框
    addPersonOption() {
      this.personForm.optionDtoList.push({
        answerDesc: "",
        key: Date.now()
      });
    },
    //删除个人题目选项输入框
    removePersonDomain(item) {
      var index = this.personForm.optionDtoList.indexOf(item);
      if (index !== -1) {
        this.personForm.optionDtoList.splice(index, 1);
      }
    },
    // 显示个人详情页面
    showEditPersonQuestion(index, data) {
      let questionId = data.id;
      this.editPersonState = true; //打开详情弹窗
      const url = `api/management/question/employee/findEmployeeQuestionAndOptionById?questionId=${questionId}`;
      this.axios.post(url).then(res => {
        // console.log("res", res.data);
        if (res.data != null) {
          this.personForm = res.data;
        }
      });
    },
    // 显示集体详情页面
    showEditDepartmentQuestion(index, data) {
      let questionId = data.id;
      this.editDepState = true; //打开详情弹窗
      const url = `api/management/question/department/findDepartmentQuestionAndOptionById?questionId=${questionId}`;
      this.axios.post(url).then(res => {
        if (res.data != null) {
          this.departmentForm = res.data;
        }
      });
    },
    // 监听关闭弹窗时重新加载数据
    closeDialog() {
      this.getQuestionList(); //重新加载列表
    },
    //获取题目列表
    getQuestionList() {
      const url = `api/management/question/list`;
      this.$axios.post(url).then(res => {
        if (res.data != null) {
          // console.log("题目列表", res.data);
          this.questionList = res.data;
        }
      });
    }
  }
};
</script>
